package org.leaf.green.b2b

class StockInDetail {

    StockIn stockIn
    String serialNumber//序号
    PurchaseDetail purchaseDetail//采购单明细
    Dealer dealer//地块
    Product product
    Warehouse warehouse
    Date life
    String unit
    BigDecimal quantity
    BigDecimal used
    BigDecimal surplus
    BigDecimal price
    BigDecimal amount
    Boolean isOver

    static belongsTo = [stockIn : StockIn]

    String toString(){
        return "$serialNumber"
    }
    
    static constraints = {
        stockIn(nullable:false)
        serialNumber(nullable:false, blank:false, maxSize : 3, unique : 'stockIn')
        purchaseDetail(nullable:false)
        dealer(nullable:false)
        product(nullable:false)
        warehouse(nullable:false)
        life(nullable:false, format : 'yyyy-MM-dd')
        unit(nullable:false, blank:false, maxSize : 4)
        quantity(nullable:false, scale : 2, min : new BigDecimal(0.01))
        used(nullable:false, scale : 2, min : new BigDecimal(0.00), validator : {val, obj ->
            return obj.quantity - val >= 0
        })
        surplus(nullable:false, scale : 2, min : new BigDecimal(0.00), validator : {val, obj ->
            return obj.quantity - val >= 0
        })
        price(nullable:false, scale:2, min : new BigDecimal(0.01))
        amount(nullable:false, scale:2, min : new BigDecimal(0.01))
        isOver(nullable:false)
    }

    static mapping = {
        table 'B2B_STOCKIN_DETAIL'
        quantity sqlType : "numeric", precision : 18, scale : 2
        used sqlType : "numeric", precision : 18, scale : 2
        surplus sqlType : "numeric", precision : 18, scale : 2
        price sqlType : "numeric", precision : 18, scale : 2
        amount sqlType : "numeric", precision : 18, scale : 2
    }
}
